void main() {
  // const count = 12;
  // print(count);

  // var name = '老万';
  // print(name);

  // num price = 21; // num 小数加整数
  // print(price);

  // String userName = '张三';
  // print(userName);

  // String poemStr = "久旱逢甘雨\n他乡遇故知\n洞房花烛夜\n金榜题名时";
  // print(poemStr);

  // bool isMarry = false;
  // isMarry ? print('已婚') : print("未婚");

  // print(isMarry == true);

  // List arr = [1, 2, 3];

  // arr.add(4); // 追加操作

  // arr.insert(0, 0);

  // arr.removeAt(3);

  // arr.addAll([4, 5, 6]);

  // arr.remove(6);

  // arr.removeLast(); // 删除最后一个

  // Map goodsMap = {'name': "张三", "age": "18", 'dender': "女"};
  // print(goodsMap);

  // goodsMap['name'] = '李四';
  // print(goodsMap);

  // goodsMap['isMarry'] = false;
  // print(goodsMap);

  // goodsMap.remove('gender');
  fun1();
  fun2();
  location(1, province: '北京', city: '北京');
  // 当使用了问号表示可选时,可以不传表示null
  location(1);
  location2(2);
  start((String name) {
    print('$name开始执行');
  });

  person p = person(name: '张三');

  // 命名构造函数的使用
  person p2 = person.of(name: '李四', gender: '女', age: 18);
}

void fun1() {
  num sarary = 10000;

  double tax = (10000 - 5000) * 0.08;

  print('你的工资为:$sarary,扣除税款后的实际工资为${sarary - tax}');
}

void fun2() {
  List fruit = [
    {'name': '草莓', 'price': 10, 'count': 10, 'selected': true},
    {'name': '榴莲', 'price': 30, 'count': 10, 'selected': true},
    {'name': '西瓜', 'price': 2, 'count': 20, 'selected': true}
  ];

  num countPrice = fruit.where((element) => element['selected']).fold(
      0.0,
      (previousValue, element) =>
          previousValue + (element['count'] * element['price']));

  print(countPrice);
}

// 可选参数 {String? province,String? city} 可以使用大括号包裹，里面的每个属性使用？表示可选
// 或者给定默认值
void location(num id, {String? province, String? city}) {
  print('id:$id,province:$province,city:$city');
}

void location2(num id, {String province = '北京', String city = '北京'}) {
  print('id:$id,province:$province,city:$city');
}

start(Function callback) {
  callback('laowan');
}

class person {
  String? name;
  String? gender;
  int? age;
  // 简写的写法  // 当属性过多的时候，可以用大括号包裹起来，这样就不必按顺序传值
  person({this.name, this.gender, this.age});

  // 命名构造函数 类名.方法(参数...)然后返回一个实例化对象
  person.of({this.name, this.gender, this.age});
}

// 继承
class student extends person {
  String? school;

  // 继承父类构造函数
  // super 当前的父类构造函数对象
  student({this.school, String? name, String? gender, int? age})
      : super(name: name, gender: gender, age: age);
}

// with混入mixin类 就可以直接调用方法
class demo {
  fun() {
    print('hashCode');
  }
}

class student2 with demo {
  goSchool() {
    fun();
  }
}
